/**
 * 省市数据业务
 * Created by benben on 14-9-20.
 */
var Page = require('../../utils/page/Page');
var Area = require('../../modules/system/area');

var AreaService = function(){
    this.model = Area;
};

//获取省数据
AreaService.prototype.findProvinces = function(callback){
    this.model.where('type').equals('1')
        .select('_id no name')
        .exec(function(err,docs){
            var page = new Page({
                totalCount : docs.length,
                data : docs
            });
            callback(page);
        });
};

/**
 * 根据省编号获取市数据
 * @param provinceNo
 * @param callback
 */
AreaService.prototype.findCities = function(provinceNo,callback){
    Area.where('type').equals('2')
        .where('provinceNo').equals(provinceNo)
        .select('_id name')
        .exec(function(err,docs){
            var page = new Page({
                totalCount : docs.length,
                data : docs
            });
            callback(page);
        });
};


module.exports = AreaService;